
#ifndef __COMPONENT_HPP__
#define __COMPONENT_HPP__

#include <array>
#include <string>
#include <cassert>
#include <memory>
#include <bitset>
#include "base_node.hpp"
#include "app.hpp"

class Node;
class Component;

constexpr std::size_t MaxComponents = 32;
using ComponentID = std::size_t;
using ComponentBitSet = std::bitset< MaxComponents >;
using ComponentArray = std::array<Component*, MaxComponents >;

class Component : public BaseNode {
    static inline ComponentID getNewComponentTypeID() {
        static ComponentID lastID = 0;
        return lastID++;
    }
    template <typename T>
    static inline ComponentID getComponentTypeID() {
        static_assert ( std::is_base_of<Component, T>::value, "" );
        static ComponentID typeID = Component::getNewComponentTypeID();
        return typeID;
    }

    static std::vector< std::unique_ptr<Component> > __pool;
public:
    enum CLASS {
        BASE,
        SPRITE,
        SCRIPT
    };
    Node* node = nullptr;
    Component();
    virtual ~Component();
    virtual Component::CLASS getClassName() const {
        return CLASS::BASE;
    }

    virtual void draw( SDLView& view ) {}
    virtual void visit( App& app ) {}

    friend class Node;
};



#endif __COMPONENT_HPP__